#include <iostream>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <signal.h>

void handler(int signo)
{
    std::cout << "signo: " << signo << std::endl;
}

int main()
{
    // 资源不足导致OS终止进程，是通过信号终止的

    // struct rlimit rl;
    // rl.rlim_cur = 1;
    // rl.rlim_max = RLIM_INFINITY; // 表示无穷
    // setrlimit(RLIMIT_CPU, &rl);
    // while(1);
    for(int i = 1; i <= 31; i++)
    {
        signal(i, handler);
    }

    struct rlimit r;
    r.rlim_cur = 1024 * 1024 * 40;
    r.rlim_max = RLIM_INFINITY;
    setrlimit(RLIMIT_AS, &r);

    int cnt = 0;
    while(1)
    {
        int *p = new int[1024 * 1024];
        cnt++;
        std::cout << cnt << std::endl;
        sleep(1);
    }

    return 0;
}